<template>
  <AmBaseTable ref="AmBaseTableRef"
               :schema="modelSchema"
               :record-config="record"
               @pagination="getList"
               :actions="[
                  {
                    label: '借阅',
                    auth: ['am:amBorrow:submit'],
                    tooltip: (row) => {
                      if(row.brStatus === '1') {
                        return '档案已借出，暂无法借阅'
                      } else {
                        return false
                      }
                    },
                    disabledCtrl: (row) => ['1'].includes(row.brStatus),
                    clickCB: this.handleBorrow,
                    buttonProps: {
                      icon: 'el-icon-upload2',
                    }
                  },
                  {
                    label: '查看',
                    auth: [],
                    clickCB: this.handleView,
                    buttonProps: {
                      icon: 'el-icon-view',
                    }
                  },
                ]">
    <template v-slot:column-brStatusName="scope">
      <el-tag :type="brStatusMap[scope.row.brStatus]">{{ scope.row.brStatusName }}</el-tag>
    </template>
    <!-- 扩展区 -->
    <template #extend>
      <ModalBorrow ref="ModalBorrowRef" />
    </template>
  </AmBaseTable>
</template>

<script>
import {delDescription, listDescription} from "@/api/am/description";
import AmBaseTable from "../../../components/AmComp/AmBaseTable.vue";
import {modelSchema} from "./model";
import ModalBorrow from "./ModalBorrow.vue";

export default {
  name: "Description",
  components: {AmBaseTable, ModalBorrow},
  data() {
    return {
      modelSchema,
      record: {
        // 显示搜索条件
        showSearch: true,
        data: [],
        total: 0,
        loading: false,
      },
      brStatusMap: {
        '0': 'success',
        '1': 'warning',
      }
    };
  },
  mounted() {
    this.$nextTick(() => this.getList());
  },
  methods: {
    /** 查询档案著录列表 */
    getList() {
      this.record.loading = true;
      const queryParams = this.$refs.AmBaseTableRef.getQueryParams();
      listDescription(queryParams).then(response => {
        this.record.data = response.rows;
        this.record.total = response.total;
        this.record.loading = false;
        console.log(this.record.data);
      });
    },
    handleBorrow(row) {
      this.$refs.ModalBorrowRef.open(row);
    },
    handleView(row) {
      let params = this.$refs.AmBaseTableRef.getQueryParams();
      let url = params.roles ? `/am/amQuery/detail/${row.id}?roleId=${params.roles}` : `/am/amQuery/detail/${row.id}`
      this.$router.push({path: url})
    }
  }
};
</script>
